'''need to make totalVisited global or pass it on'''
def dfs(graph, start, visited=None):
    if visited is None:
        visited = set()
    visited.add(start)
    links = [link for link in graph[start].links]''' get a list of all connected nodes through links field in each juc'''
    neighbours = map((lambda link: link.target),links)
    for next in [x for x in neighbours if x not in visited and x not in totalVisited]:
        dfs(graph, next, visited)
    return visited


'''half pseudo code...'''
def getComponents(graph):
	remaining = set(range(len(graph)))
	curVisited = set()
	totalVisited = set()

	while len(remaining) > 0 :
		curVisited = dfs(roads,remaining[0], None)
		totalVisited += curVisited
		remaining -= curVisited
		listOfSets.append(curVisited)